mini.parse();
var grid=mini.get("grid1");  //获取grid的id
$(document).ready(function(){        //先渲染无数据日历

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    if($('.calendar').length > 0){
        $('.calendar').fullCalendar({
            locale:'zh-cn',
            buttonText: {
                today: '跳转到今天',
                month: '月视图',
                week: '周视图',
                day: '日视图'
            },
            allDayText: "全天",
            timeFormat: {
                '': 'H:mm{-H:mm}'
            },
            weekMode: "variable",
            columnFormat: {
                month: 'dddd',
                week: 'dddd M-d',
                day: 'dddd M-d'
            },
            titleFormat: {
                month: 'yyyy年 MMMM月',
                week: "[yyyy年] MMMM月d日 { '&#8212;' [yyyy年] MMMM月d日}",
                day: 'yyyy年 MMMM月d日 dddd'
            },
            monthNames: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"],
            dayNames: ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
            header: {
                left: 'prev,next,today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay',
            },

            editable: true,
        });
    }

});
//渲染左侧表格grid数据
$(function () {
    $.ajax({
        url:"http://localhost:8080/DSMP/carInfo/getAll.do",
        type:"post",
        success:function (data) {
            grid.setData(data.obj);
            console.log(data.obj)

        }
    })
})
//给表格绑定一个双击事件
grid.on("rowdblclick",function () {
   var row=grid.getSelected().carInfoId;
    var events=[];
   $.ajax({
       url:"http://localhost:8080/DSMP/carApply/getApplyByCarId.do?carId="+row,
       type:"post",
       contentType: "application/json",
       success:function (data) {
        console.log(data);
        // 遍历后端日程数据
           data.obj.length && data.obj.forEach(item => {
               // 时间格式处理
               console.log('foreachItem',item.start)

               item.start = new Date(...timeCovert(item.start))
               item.end = new Date(...timeCovert(item.end))

               events.push(item)

           });
           console.log(events);
           //先清空子节点然后在渲染日历数据
           $("#boxpo").html("").append("<div class=\"box-head\">\n" +
               "\n" +
               "                    <h3>Calendar</h3>\n" +
               "\n" +
               "                </div>\n" +
               "\n" +
               "                <div class=\"box-content box-nomargin\">\n" +
               "\n" +
               "                    <div class=\"calendar\"></div>\n" +
               "\n" +
               "                </div>");
            // 日程设calendar置项，可在官网查看具体配置属性
           $('.calendar').length && $('.calendar').fullCalendar({
               buttonText: {
                   today: '跳转今天',
                   month: '月视图',
                   week: '周视图',
                   day: '日视图'
               },
               allDayText: "全天",
               timeFormat: {
                   '': 'H:mm{-H:mm}'
               },
               weekMode: "variable",
               columnFormat: {
                   month: 'dddd',
                   week: 'dddd M-d',
                   day: 'dddd M-d'
               },
               titleFormat: {
                   month: 'yyyy年 MMMM月',
                   week: "[yyyy年] MMMM月d日 { '&#8212;' [yyyy年] MMMM月d日}",
                   day: 'yyyy年 MMMM月d日 dddd'
               },
               monthNames: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"],
               dayNames: ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
                   header: {
                       left: 'prev,next,today',
                       center: 'title',
                       right: 'month,agendaWeek,agendaDay',

                   },

                   editable: true,

                   events
               });
       }
   })
})

// 后端时间数据转换函数
const timeCovert = (newDateStr) => {
    console.log(newDateStr)
    // new Date(2020,02,17,14,55,04)（后端02代表2月份） ===》  new Date(2020,1,17,14,55,04) （js2月份表示法）
    let arr = newDateStr.split('(')[1].slice(0,-1).split(',')
    console.log('arr',arr)
    arr[1] = parseInt(arr[1].slice(-1)) - 1
    arr = arr.map(item => parseInt(item))
    return arr
}